package com.vrv.netmgr;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.vrv.common.UrlPrefix;
import com.vrv.common.resolver.Page;
import com.vrv.common.resolver.RequestParameter;
import com.vrv.common.util.CheckNetStatus;
import com.vrv.netmgr.database.DatabaseHelper;

public class EdpApplication extends Application {

    private static final String TAG = EdpApplication.class.getSimpleName();

    private static final boolean DEBUG = true;

    /** 查询条件暂存 */
    public static RequestParameter parameter = null;

    /** 分页对象暂存 */
    public static Page page;

    private SQLiteDatabase mDatabase;

    private DatabaseHelper mDatabaseHelper;

    private static EdpApplication sEdpApp;

    // 网络状态
    private static boolean netStatus = false;

    public static boolean isNetStatus() {
        return netStatus;
    }

    public static void setNetStatus(boolean netStatus) {
        EdpApplication.netStatus = netStatus;
    }

    @Override
    public void onCreate() {
        if (DEBUG)
            Log.v(TAG, "EdpApplication--onCreate()");

        sEdpApp = this;

        CheckNetStatus.init(this);
        UrlPrefix.init(this);
    }

    public static EdpApplication getsEdpApp() {
        return sEdpApp;
    }

    /**
     * 获取数据相关应用
     *
     * @return
     */
    public DatabaseHelper getDatabaseHelper() {
        if (null == this.mDatabaseHelper) {
            this.mDatabaseHelper = ((DatabaseHelper) OpenHelperManager.getHelper(this, DatabaseHelper.class));
            this.mDatabase = this.mDatabaseHelper.getWritableDatabase();
        }
        return this.mDatabaseHelper;
    }

    /**
     * 获取数据相关应用
     *
     * @return
     */
    public SQLiteDatabase getSQLiteDatabase() {
        if (null == this.mDatabase) {
            this.mDatabaseHelper = ((DatabaseHelper) OpenHelperManager.getHelper(this, DatabaseHelper.class));
            this.mDatabase = this.mDatabaseHelper.getWritableDatabase();
        }
        return this.mDatabase;
    }
}
